
#include "StdAfx.h"

#include <AzCore/Serialization/SerializeContext.h>
#include <AzCore/Serialization/EditContext.h>

#include "PlayFab<%- gemName %>TestSystemComponent.h"
<% if (hasClientOptions) { %>
#include <PlayFab<%- gemName %>Sdk/PlayFab<%- gemName %>_ClientBus.h>
#include <PlayFab<%- gemName %>Sdk/PlayFab<%- gemName %>_SettingsBus.h>
using namespace PlayFab<%- gemName %>Sdk;
<% } %>
namespace PlayFab<%- gemName %>Test
{
    void PlayFab<%- gemName %>TestSystemComponent::Reflect(AZ::ReflectContext* context)
    {
        if (AZ::SerializeContext* serialize = azrtti_cast<AZ::SerializeContext*>(context))
        {
            serialize->Class<PlayFab<%- gemName %>TestSystemComponent, AZ::Component>()
                ->Version(0)
                ->SerializerForEmptyClass();

            if (AZ::EditContext* ec = serialize->GetEditContext())
            {
                ec->Class<PlayFab<%- gemName %>TestSystemComponent>("PlayFab<%- gemName %>Test", "[Description of functionality provided by this System Component]")
                    ->ClassElement(AZ::Edit::ClassElements::EditorData, "")
                    // ->Attribute(AZ::Edit::Attributes::Category, "") Set a category
                    ->Attribute(AZ::Edit::Attributes::AppearsInAddComponentMenu, AZ_CRC("System"))
                    ->Attribute(AZ::Edit::Attributes::AutoExpand, true)
                    ;
            }
        }
    }

    void PlayFab<%- gemName %>TestSystemComponent::GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided)
    {
        provided.push_back(AZ_CRC("PlayFab<%- gemName %>TestService"));
    }

    void PlayFab<%- gemName %>TestSystemComponent::GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible)
    {
        incompatible.push_back(AZ_CRC("PlayFab<%- gemName %>TestService"));
    }

    void PlayFab<%- gemName %>TestSystemComponent::GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required)
    {
        (void)required;
    }

    void PlayFab<%- gemName %>TestSystemComponent::GetDependentServices(AZ::ComponentDescriptor::DependencyArrayType& dependent)
    {
        (void)dependent;
    }

    void PlayFab<%- gemName %>TestSystemComponent::Init()
    {
    }

    void PlayFab<%- gemName %>TestSystemComponent::Activate()
    {
        PlayFab<%- gemName %>TestRequestBus::Handler::BusConnect();

        LoginOrRegister();
    }

    void PlayFab<%- gemName %>TestSystemComponent::Deactivate()
    {
        PlayFab<%- gemName %>TestRequestBus::Handler::BusDisconnect();
    }
<% if (hasClientOptions) { %>
    void OnLoginOrRegister(const ClientModels::LoginResult& result, void* customData)
    {
        auto playFabId = result.PlayFabId;
    }
    void OnSharedError(const PlayFabError& error, void* customData)
    {
        auto playFabId = "failed to log in";
    }
<% } %>
    void PlayFab<%- gemName %>TestSystemComponent::LoginOrRegister()
    {
<% if (hasClientOptions) { %>
        PlayFab<%- gemName %>_SettingsRequestBus::Broadcast(&PlayFab<%- gemName %>_SettingsRequests::SetTitleId, AZStd::string("6195"));

        ClientModels::LoginWithCustomIDRequest request;
        request.CustomId = "GettingStartedGuide";
        request.CreateAccount = true;
        EBUS_EVENT(PlayFab<%- gemName %>_ClientRequestBus, LoginWithCustomID, request, OnLoginOrRegister, OnSharedError, nullptr);
<% } %>
    }
}
